package com.atguigu.springcloud.controller;

import com.atguigu.springcloud.common.CommonResult;
import com.atguigu.springcloud.entities.Payment;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

/**
 * @ClassName : com.atguigu.springcloud.controller.OrderController
 * @Description : 类描述
 * Created by cyd on 2021-09-15 19:51:50
 */
@RestController
@Slf4j
public class OrderController {
    @Resource
    private RestTemplate restTemplate;

    // public static final String PAYMENT_URL = "http://localhost:8001";
    // 不要调用具体的ip+端口，而是把这一步交给eureka
    public static final String PAYMENT_URL = "http://CLOUD-PAYMENT-SERVICE";

    @PostMapping("/consumer/payment/creat")
    public CommonResult<Payment> creat(@RequestBody Payment payment) {
        log.info("payment:{}", payment.toString());
        return restTemplate.postForObject(PAYMENT_URL + "/payment/creat",
                payment, CommonResult.class);
    }

    @GetMapping("/consumer/payment/get/{id}")
    public CommonResult<Payment> getPayment(@PathVariable("id") Long id) {
        log.info("id:{}", id.toString());
        return restTemplate.getForObject(PAYMENT_URL + "/payment/get/" + id,
                CommonResult.class);
    }

}
